package com.yanxml.springboot.core.listener.custom.business_event.listener;

import com.yanxml.springboot.core.listener.custom.business_event.event.MyCustomApplicationEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

/**
 * 自定义监听器, 监听自定义事件.
 */
@Configuration
public class MyCustomerEventListener implements ApplicationListener<MyCustomApplicationEvent> {

    @Override
    public void onApplicationEvent(MyCustomApplicationEvent event) {
        if (Objects.isNull(event)) {
            return;
        }
        if(event instanceof MyCustomApplicationEvent){
            System.out.println("handler custom event, event name" + event.getName());
        }
//        if(event instanceof ApplicationEvent){
//            System.out.println("handler custom event, event name" + event.getName());
//        }
        System.out.println("handler custom event, event name" + event.getName());
    }
}
